package com.qffx.moviebase.adapter.find;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qffx.moviebase.R;
import com.qffx.moviebase.bean.find.findmovie.BaseEntity;
import com.qffx.moviebase.bean.find.findmovie.MovieCastEntity;
import com.qffx.moviebase.bean.find.findmovie.MovieCommentListEntity;
import com.qffx.moviebase.bean.find.findmovie.MovieFilmResourceEntity;
import com.qffx.moviebase.bean.find.findmovie.MoviePhotoEntity;
import com.qffx.moviebase.bean.find.findmovie.MovieRelationArticleEntity;
import com.qffx.moviebase.bean.find.findmovie.MovieSummaryEntity;
import com.qffx.moviebase.bean.find.findmovie.MovieTrailerEntity;

import java.util.List;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

/**
 * Created by lx on 2017/2/10.
 */

public class FindMovieAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<BaseEntity> list;
    private Context context;

    public FindMovieAdapter(List<BaseEntity> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == 1) {
            View view = LayoutInflater.from(context).inflate(R.layout.movie_item1, parent, false);
            return new ViewHolder1(view);
        } else if (viewType == 2) {
            View view = LayoutInflater.from(context).inflate(R.layout.movie_item2, parent, false);
            return new ViewHolder2(view);
        } else if (viewType == 3) {
            View view = LayoutInflater.from(context).inflate(R.layout.movie_item3, parent, false);
            return new ViewHolder3(view);
        } else if (viewType == 4) {
            View view = LayoutInflater.from(context).inflate(R.layout.movie_item4, parent, false);
            return new ViewHolder4(view);
        } else if (viewType == 5) {
            View view = LayoutInflater.from(context).inflate(R.layout.movie_item5, parent, false);
            return new ViewHolder5(view);
        } else if (viewType == 6) {
            View view = LayoutInflater.from(context).inflate(R.layout.movie_item6, parent, false);
            return new ViewHolder6(view);
        } else if (viewType == 7) {
            View view = LayoutInflater.from(context).inflate(R.layout.movie_item7, parent, false);
            return new ViewHolder7(view);
        } else {
            return null;
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        int type = getItemViewType(position);
        if (type == 1) {
            MovieFilmResourceEntity entity = (MovieFilmResourceEntity) list.get(position);
            Log.e("11111", "aaaaaa");
            ((ViewHolder1) holder).tv.setText(entity.getBean().getTitle());
        } else if (type == 2) {
            MovieSummaryEntity entity = (MovieSummaryEntity) list.get(position);
            Log.e("22222", "aaaaaa");

            ((ViewHolder2) holder).tv.setText(entity.getSummary());
        } else if (type == 3) {
            MovieCastEntity entity = (MovieCastEntity) list.get(position);
            Log.e("33333", "aaaaaa");

            ((ViewHolder3) holder).tv.setText(entity.getCasts().size() + "");
        } else if (type == 4) {
            MovieTrailerEntity entity = (MovieTrailerEntity) list.get(position);
            ((ViewHolder4) holder).jc.setUp(entity.getBean().get(0).getResource_url(), JCVideoPlayer.SCREEN_LAYOUT_NORMAL, "ceshi");
            ((ViewHolder4) holder).jc.backButton.setVisibility(View.GONE);
            ((ViewHolder4) holder).jc.thumbImageView.setScaleType(ImageView.ScaleType.FIT_XY);
            Log.e("44444", "aaaaaa");
        } else if (type == 5) {
            Log.e("55555", "aaaaaa");

            MoviePhotoEntity entity = (MoviePhotoEntity) list.get(position);
            ((ViewHolder5) holder).tv.setText(entity.getUrl().size() + "");
        } else if (type == 6) {
            Log.e("66666", "aaaaaa");

            MovieRelationArticleEntity entity = (MovieRelationArticleEntity) list.get(position);
            ((ViewHolder6) holder).tv.setText(entity.getList().size() + "");
        } else if (type == 7) {
            Log.e("77777", "aaaaaa");

            MovieCommentListEntity entity = (MovieCommentListEntity) list.get(position);
            ((ViewHolder7) holder).tv.setText(entity.getList().size() + "");
        }
    }

    @Override
    public int getItemViewType(int position) {
        BaseEntity baseEntity = list.get(position);
        if (baseEntity instanceof MovieFilmResourceEntity) {
            return 1;
        } else if (baseEntity instanceof MovieSummaryEntity) {
            return 2;
        } else if (baseEntity instanceof MovieCastEntity) {
            return 3;
        } else if (baseEntity instanceof MovieTrailerEntity) {
            return 4;
        } else if (baseEntity instanceof MoviePhotoEntity) {
            return 5;
        } else if (baseEntity instanceof MovieRelationArticleEntity) {
            return 6;
        } else if (baseEntity instanceof MovieCommentListEntity) {
            return 7;
        }
        return super.getItemViewType(position);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder1 extends RecyclerView.ViewHolder {
        private TextView tv;

        public ViewHolder1(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.text);
        }
    }

    class ViewHolder2 extends RecyclerView.ViewHolder {
        private TextView tv;

        public ViewHolder2(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.text);

        }
    }

    class ViewHolder3 extends RecyclerView.ViewHolder {
        private TextView tv;

        public ViewHolder3(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.text);

        }
    }

    class ViewHolder4 extends RecyclerView.ViewHolder {
        private JCVideoPlayerStandard jc;

        public ViewHolder4(View itemView) {
            super(itemView);
            jc = (JCVideoPlayerStandard) itemView.findViewById(R.id.jc_play);

        }
    }

    class ViewHolder5 extends RecyclerView.ViewHolder {
        private TextView tv;

        public ViewHolder5(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.text);

        }
    }

    class ViewHolder6 extends RecyclerView.ViewHolder {
        private TextView tv;

        public ViewHolder6(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.text);

        }
    }

    class ViewHolder7 extends RecyclerView.ViewHolder {
        private TextView tv;

        public ViewHolder7(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.text);

        }
    }


}
